#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by master on 2017/3/13
import re
import js2py
import requests
from bs4 import BeautifulSoup

url = "http://www.pbc.gov.cn/zhengwugongkai/127924/128041/2951606/1923625/1923629/2868403/index.html"


def getHtml(url):
    header = {
        'Connection': 'keep-alive',
        'Cache-Control': 'max-age=0',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Accept-Encoding': 'gzip, deflate, sdch',
        'Accept-Language': 'zh-CN,zh;q=0.8', }
    html = requests.get(url=url, headers=header).content
    return html.decode('utf-8')


def make_soup(html):
    soup = BeautifulSoup(html, "lxml")

    js_func = soup.find("script").text

    return js_func


def executeJS(js_func_string):
    func = js2py.eval_js(js_func_string[6:len(js_func_string) - 1])
    return func


html = getHtml(url)

soup = make_soup(html)

js_source = executeJS(soup)

print(js_source)
